package com.itboye.pondteam.pondteam;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.pondteam.R;
import com.itboye.pondteam.base.BaseActivity;
import com.itboye.pondteam.presenter.UserPresenter;
import com.itboye.pondteam.utils.Const;
import com.itboye.pondteam.utils.loadingutil.MAlert;
import com.itboye.pondteam.volley.ResultEntity;

import java.util.Observable;
import java.util.Observer;

import static com.itboye.pondteam.utils.EmptyUtil.getSp;


public class PondTeamFeedbackActivity extends BaseActivity implements TextWatcher, Observer {
    Button btnSend;
    EditText ediContent, edit_contact;
    ImageView fankuiback;
    CheckBox CheckBox;
    TextView device_type;
    //	AqDeviceMessageType messageType;
    int progress = 0;
    private final int SUCCESS = 0;
    int type = 0;
    UserPresenter userPresenter;
    String deviceTypeName = "";

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub com.itboye.sunsunhome.www.aq.PondTeamFeedbackActivity
        super.onCreate(arg0);
        setContentView(R.layout.activity_pondtam_feedback);
        userPresenter = new UserPresenter(this);
        int deviceType = getIntent().getIntExtra("device_type", 0);
        deviceTypeName = "S01";
        device_type.setText(getString(R.string.guolvtong) + "  " + getString(R.string.wentifankui));
        fankuiback = (ImageView) findViewById(R.id.fankuiback);
        CheckBox = (android.widget.CheckBox) findViewById(R.id.checkbox);

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
                                  int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.fankuiback) {
            finish();

        } else if (i == R.id.btnSend) {//S01: 过滤桶 S02: 加热棒 S03: 变频水泵
            String contact = edit_contact.getText().toString();
            if (contact.equals("")) {
                AlertShow("请输入联系方式！");
                return;
            }
            String content = ediContent.getText().toString();
            if (content.equals("")) {
                AlertShow("请输入反馈内容！");
                return;
            }
            userPresenter.feedback(deviceTypeName, "", getSp(Const.EMAIL), contact, getSp(Const.UID), content);

        }
    }

    @Override
    public void update(Observable o, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            if (entity.getCode() != 0) {
                MAlert.alert(entity.getMsg());
                return;
            }
            if (entity.getEventType() == UserPresenter.feedbacksuccess) {
                MAlert.alert(entity.getData(), Gravity.CENTER, getResources().getColor(R.color.main_green));
                finish();
            } else if (entity.getEventType() == UserPresenter.feedbackfail) {
                MAlert.alert(entity.getData());
            }
        }
    }
}
